﻿<Page x:Class="PasswordProvider.View.SitesListViewPage"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:behavior="clr-namespace:PasswordProvider.View.Behaviors"
    KeepAlive="True"
	AllowDrop="True" 
	Title="{Binding DisplayName}"
	ToolTip="{Binding ToolTip}"
	IsEnabled="{Binding IsEnabled}"
    Background="{StaticResource WindowBrush}"
	FocusManager.FocusedElement="{Binding ElementName=_itemsListBox}"
    behavior:EventCommands.DropCommand="{Binding DropDataCommand.Command}"
	behavior:EventCommands.DragEnterCommand="{Binding CanDropDataCommand.Command}"
    behavior:EventCommands.DragOverCommand="{Binding CanDropDataCommand.Command}"
    >
    <Page.Resources>
        
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="Dictionary/SitesListViewPageResources.xaml" />
			</ResourceDictionary.MergedDictionaries>
		</ResourceDictionary>

    </Page.Resources>

	<Page.InputBindings>
		<!-- Binding commands to KeyBinding, possible because of class CommandBindingExtension -->
		<KeyBinding Key="Delete" Command="{behavior:CommandBinding DeleteCommand.Command}" />
		<KeyBinding Key="Right" Command="{behavior:CommandBinding ShowSitePropertiesCommand.Command}" />
		<KeyBinding Key="C" Modifiers="Control" Command="{behavior:CommandBinding CopyCommand.Command}" />
		<KeyBinding Key="S" Modifiers="Control" Command="{behavior:CommandBinding SendKeysCommand.Command}" />
        <KeyBinding Key="V" Modifiers="Control" Command="{behavior:CommandBinding PasteCommand.Command}" />
        <KeyBinding Key="N" Modifiers="Control" Command="{behavior:CommandBinding CreateNewLogOnSiteCommand.Command}" />
        <KeyBinding Key="K" Modifiers="Control" Command="{behavior:CommandBinding CreateNewCreditCardCommand.Command}" />
        <KeyBinding Key="G" Modifiers="Control" Command="{behavior:CommandBinding CreateNewGenericSiteCommand.Command}" />
	</Page.InputBindings>

	<Page.ContextMenu>
		<ContextMenu>
            <MenuItem Header="Create New">                          
			    <MenuItem 
				    Header="{Binding CreateNewLogOnSiteCommand.DisplayName}"
				    ToolTip="{Binding CreateNewLogOnSiteCommand.ToolTip}"                       
				    Command="{Binding CreateNewLogOnSiteCommand.Command}"/>
			    <MenuItem 
				    Header="{Binding CreateNewCreditCardCommand.DisplayName}"
				    ToolTip="{Binding CreateNewCreditCardCommand.ToolTip}"
				    Command="{Binding CreateNewCreditCardCommand.Command}"/>
                <MenuItem 
				    Header="{Binding CreateNewGenericSiteCommand.DisplayName}"
				    ToolTip="{Binding CreateNewGenericSiteCommand.ToolTip}"
				    Command="{Binding CreateNewGenericSiteCommand.Command}"/>
            </MenuItem>
			<Separator />
			<MenuItem 
				InputGestureText="->"
				Visibility="{Binding ShowSitePropertiesCommand.Visibility}"
				Header="{Binding ShowSitePropertiesCommand.DisplayName}"
				ToolTip="{Binding ShowSitePropertiesCommand.ToolTip}"
				Command="{Binding ShowSitePropertiesCommand.Command}"/>
			<MenuItem 
				InputGestureText="Del"
				Visibility="{Binding DeleteCommand.Visibility}"
				Header="{Binding DeleteCommand.DisplayName}"
				ToolTip="{Binding DeleteCommand.ToolTip}"
				Command="{Binding DeleteCommand.Command}"/>
            <MenuItem 
				Visibility="{Binding DeleteTagCommand.Visibility}"                
				Header="{Binding DeleteTagCommand.DisplayName}"
				ToolTip="{Binding DeleteTagCommand.ToolTip}"
				Command="{Binding DeleteTagCommand.Command}"/>
			<Separator />
            <MenuItem
				InputGestureText="Ctrl+V"
				Visibility="{Binding PasteCommand.Visibility}"
				Header="{Binding PasteCommand.DisplayName}"
				ToolTip="{Binding PasteCommand.ToolTip}"
				Command="{Binding PasteCommand.Command}"/>
			<MenuItem 
				InputGestureText="Ctrl+C"
				Visibility="{Binding CopyCommand.Visibility}"
				Header="{Binding CopyCommand.DisplayName}"
				ToolTip="{Binding CopyCommand.ToolTip}"
				Command="{Binding CopyCommand.Command}"/>
			<MenuItem 
				InputGestureText="Ctrl+S"
				Visibility="{Binding SendKeysCommand.Visibility}"
				Header="{Binding SendKeysCommand.DisplayName}"
				ToolTip="{Binding SendKeysCommand.ToolTip}"
				Command="{Binding SendKeysCommand.Command}"/>
		</ContextMenu>
	</Page.ContextMenu>

	<Page.Content>
		<ListBox x:Name="_itemsListBox" Margin="4"
                 PreviewKeyDown="ListBox_PreviewKeyDown"
				 Background="{StaticResource WindowBrush}"
				 ItemsSource="{Binding ItemsSource}"
				 IsSynchronizedWithCurrentItem="True"    
				 Style="{StaticResource SitesListViewListBoxStyle}"                 
				>
            <ListBox.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander Style="{StaticResource SitesListGroupStyleExpanderStyle}"
                                                  Tag="{Binding Name}"
                                                  PreviewMouseDown="Group_PreviewMouseDown"
                                                  Collapsed="Group_Collapsed" 
                                                  Expanded="Group_Expanded">
                                            <Expander.Content>
                                                <ItemsPresenter />
                                            </Expander.Content>
                                        </Expander>

                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListBox.GroupStyle>
		</ListBox>
	</Page.Content>

</Page>
